package com.itboye.ihomebank.me;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.adapter.WodeFangyYuanAdapter;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.bean.WoDeFangYuanBean;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.custom.XListView;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;
/**
 * 我的房源
 *
 */
public class WodeFangyuanActivity extends BaseOtherActivity implements Observer {

	private XListView xlistView;
	private HousePresenter housePresenter;
	private String uid;
	private WodeFangyYuanAdapter adapter;
	private List<WoDeFangYuanBean> arrayHouse;
	private ImageView imgEmpty, close_icon;
	private TextView add_shap_title_tv;

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;

		default:
			break;
		}
	}

	@Override
	protected int layout_id() {
		return R.layout.activity_wodefangyuan;
	}

	@Override
	protected void onInitController() {

	}

	@Override
	protected void onInit() {
		xlistView.setPullRefreshEnable(false);
		uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
		add_shap_title_tv.setText("我的房源");
		arrayHouse = new ArrayList<WoDeFangYuanBean>();
		adapter = new WodeFangyYuanAdapter(this, arrayHouse,
				R.layout.item_wodeqiuzu);
		xlistView.setAdapter(adapter);
		housePresenter = new HousePresenter(this);
		housePresenter.getWoDeFaBu(uid);
	}

	@Override
	protected void onReadIntent(Bundle bundle) {

	}

	@Override
	public void update(Observable observable, Object data) {
		
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == HousePresenter.woDeFaBuList_success) {
				List<WoDeFangYuanBean> woDeFangYuanBeans = (List<WoDeFangYuanBean>) entity
						.getData();
				if (woDeFangYuanBeans != null) {
					if (woDeFangYuanBeans.size() <= 0) {
						imgEmpty.setVisibility(View.VISIBLE);
					}else{
						imgEmpty.setVisibility(View.GONE);
						arrayHouse.addAll(woDeFangYuanBeans);
						adapter.notifyDataSetChanged();
					}
				}if (woDeFangYuanBeans.size() <= 0) {
					imgEmpty.setVisibility(View.VISIBLE);
				}
				
			} else if (entity.getEventType() == HousePresenter.woDeFaBuList_fail) {
				ByAlert.alert(entity.getData());
			}
		}
	}

}
